package container;

import org.junit.Test;

import java.util.*;
import java.util.concurrent.ConcurrentHashMap;

/**
 * Created by liuwei on 2018/3/21.
 */
public class Container {

    @Test
    public void HashMapTest(){
        System.out.println("HashMapTest");
        long a1 = System.currentTimeMillis();
        Map<String,String> map = new HashMap<>();
        for(int i= 0;i< 100000;i++){
            map.put(i+"","value"+1);
        }
        long a2 = System.currentTimeMillis();
        System.out.println(a2-a1);
        for(int i= 0;i< 100000;i++){
            map.get(i+"");
        }
        long a3 = System.currentTimeMillis();
        System.out.println(a3-a2);
        for(int i= 0;i< 100000;i++){
            map.remove(i+"");
        }
        long a4 = System.currentTimeMillis();
        System.out.println(a4-a3);


    }
    @Test
    public void ConcurrentHashMapTest(){
        System.out.println("ConcurrentHashMapTest");
        long a1 = System.currentTimeMillis();
        Map<String,String> map = new ConcurrentHashMap<>();
        for(int i= 0;i< 100000;i++){
            map.put(i+"","value"+1);
        }
        long a2 = System.currentTimeMillis();
        System.out.println(a2-a1);


    }

    @Test
    public void VectorTest(){
        System.out.println("VectorTest");
        long a1 = System.currentTimeMillis();
        Vector<String> vector = new Vector<>();
        for(int i= 0;i< 100000;i++){
            vector.add("value"+1);
        }
        long a2 = System.currentTimeMillis();
        System.out.println(a2-a1);

    }

    @Test
    public void ArrayListTest(){
        System.out.println("ArrayListTest");
        long a1 = System.currentTimeMillis();
        List<String> list = new ArrayList<>();
        for(int i= 0;i< 100000;i++){
            list.add("value"+i);
        }
        long a2 = System.currentTimeMillis();
        System.out.println(a2-a1);
        for(int i= 0;i< 100000;i++){
            list.get(i);
        }

        long a3 = System.currentTimeMillis();
        System.out.println(a3-a2);


        for(int i= 0;i< 100000;i++){
            list.add(i,"value"+i);
        }

        long a4 = System.currentTimeMillis();
        System.out.println(a4-a3);
        for(int i= 0;i< 100000;i++){
            list.remove("value"+i);
        }
        long a5 = System.currentTimeMillis();
        System.out.println(a5-a4);

    }

    @Test
    public void HashSetTest(){
        System.out.println("HashSetTest");
        long a1 = System.currentTimeMillis();
        Set<String> set = new HashSet<>();
        for(int i= 0;i< 100000;i++){
            set.add("value"+1);
        }
        long a2 = System.currentTimeMillis();
        System.out.println(a2-a1);

    }
}
